﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Lib.Helper;
using MSIACCSL2.ViewModels;
using WcfService1.DTO;

namespace MSIACCSL2.Views.COA
{
    public partial class DetailSaldoHutang : ChildWindow
    {
        public SaldoHutangViewModel ViewModel
        {
            get { return (SaldoHutangViewModel) this.DataContext; }
        }
        public DetailSaldoHutang()
        {
            InitializeComponent();
            EventAggregator.RegisterMessage("SaveSaldoAwalHutangFinished",(x)=>
                                                                              {
                                                                                  this.DialogResult = true;

                                                                              });
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
             ViewModel.SaveSaldoAwalHutang();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void btnAdd_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var saldoAwalHutang = new SaldoAwalHutang();
            saldoAwalHutang.Suppliers = ViewModel.SaldoAwalHutangs.FirstOrDefault().Suppliers;
            ViewModel.SaldoAwalHutangs.Add(saldoAwalHutang);
            
        }

        private void btnDelete_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ViewModel.SaldoAwalHutangs.Remove((SaldoAwalHutang) (sender as Button).DataContext);
        }
    }
}

